import { modelsPoint } from '@/config';

export function addModels(map: any) {
  const TMap = (window as any).TMap;
  if (!TMap) throw new Error('TMap 未注入');

  const instances: any[] = [];
  modelsPoint.forEach((cfg) => {
    const model = new TMap.model.GLTFModel({ url: cfg.url, map, id: cfg.id, position: new TMap.LatLng(...cfg.position), scale: cfg.scale, rotation: cfg.rotation });
    model.on('loaded', () => console.log('模型', cfg.id, '加载成功'));
    model.on('error', () => console.error('模型', cfg.id, '加载失败'));
    model.on('click', () => console.log('模型', cfg.id, '点击'));
    instances.push(model);
  });

  return instances;
}

export default { addModels };
